//
//  YJDZFffView.m
//  sigleAPP
//
//  Created by SKL on 2017/11/17.
//  Copyright © 2017年 SKL. All rights reserved.
//
#define H 40
#import "XOWMzfshitu.h"
#import "XOWMOrderLBL.h"
#import "XOWMSegBtn.h"
#import "XOWMProduct.h"
@interface XOWMzfshitu ()
@property (nonatomic, strong) XOWMLabel *orderInfoLBL;
@property (nonatomic, strong) XOWMCustomButton *enterBtn;
@property (nonatomic, strong) XOWMLabel *zffsLBL;
//@property (nonatomic, strong) XOWMOrderLBL *themeLBL;
@property (nonatomic, strong) XOWMOrderLBL *gameLBL;
@property (nonatomic, strong) XOWMOrderLBL *moneyLBL;
@property (nonatomic, strong) UIView *line;
@end
@implementation XOWMzfshitu
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.imageView.hidden = NO;
        self.layer.cornerRadius = 5.0;
        self.layer.masksToBounds = YES;
        self.orderInfoLBL.hidden = self.line.hidden = self.enterBtn.hidden = NO;
        self.gameLBL.hidden = self.moneyLBL.hidden = NO;
        self.zffsLBL.hidden = NO;
        self.backgroundColor = ([XOWMHelper shareHelp].style == XOWMPlatformStyleImage)?[UIColor clearColor]:[UIColor whiteColor];
    }
    return self;
}
- (XOWMImageView *)imageView
{
    if (!_imageView)
    {
        _imageView = [[XOWMImageView alloc] init];
        [self addSubview:_imageView];
        _imageView.c_edges.equal(UIEdgeInsetsZero);
    }
    return _imageView;
}

- (XOWMLabel *)orderInfoLBL
{
    if (!_orderInfoLBL)
    {
        _orderInfoLBL = [[XOWMLabel alloc]initWithText:@"订单信息"];
        _orderInfoLBL.font = [UIFont systemFontOfSize:19 weight:UIFontWeightBold];
        _orderInfoLBL.textColor = TEXT_BLACK_COLOR;
        [_orderInfoLBL sizeToFit];
        [self addSubview:_orderInfoLBL];
        _orderInfoLBL.c_left.equal(self).with.coffset(10);
        _orderInfoLBL.c_top.equal(self).with.coffset(10);
        _orderInfoLBL.c_size.equal(_orderInfoLBL.bounds.size);
    }
    return _orderInfoLBL;
}

- (XOWMButton *)cancelBtn
{
    if (!_cancelBtn)
    {
        _cancelBtn = [[XOWMButton alloc] init];
        _cancelBtn.style = YJDButtonTitleStyleCameo;
        _cancelBtn.height = ([XOWMHelper shareHelp].style == XOWMPlatformStyleImage)?TITLE_HEIGHT:TITLE_HEIGHT * 1.5;
        [_cancelBtn setValue:[UIFont systemFontOfSize:15.0 weight:UIFontWeightLight] forKeyPath:@"_titleLBL.font"];
        [_cancelBtn addTarget:self action:@selector(yjd_aciontForCancelBtn) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_cancelBtn];
        _cancelBtn.c_centerY.equal(self.orderInfoLBL);
        if ([XOWMHelper shareHelp].style == XOWMPlatformStyleDefault)
            _cancelBtn.c_right.equal(self).with.coffset(0);
        else
            _cancelBtn.c_right.equal(self);
    }
    return _cancelBtn;
}

- (UIView *)line
{
    if (!_line)
    {
        _line = [[UIView alloc]init];
        _line.backgroundColor = RGBA(223, 223, 223, 1.0);
        [self addSubview:_line];
        _line.c_top.equal(self.orderInfoLBL.c_bottom).with.coffset(GAP);
        _line.c_left.equal(self).with.coffset(GAP);
        _line.c_right.equal(self).with.coffset(-GAP);
        _line.c_height.equal(1);
    }
    return _line;
}


- (XOWMCustomButton *)enterBtn
{
    if (!_enterBtn)
    {
        _enterBtn = [[XOWMCustomButton alloc]init];
        [_enterBtn setTitle:@"购买" forState:UIControlStateNormal];
        [_enterBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_enterBtn setTitleColor:TEXT_GRAY_COLOR forState:UIControlStateHighlighted];
        [_enterBtn setBackgroundColor:[XOWMHelper shareHelp].color ];
        _enterBtn.showLayerBorder = YES;
        [_enterBtn addTarget:self action:@selector(yjd_actionForEnterBtn) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_enterBtn];
        _enterBtn.c_left.equal(self).with.coffset(100);
        _enterBtn.c_right.equal(self).with.coffset(-100);
        _enterBtn.c_bottom.equal(self).with.coffset(- 8);
        _enterBtn.c_height.equal(40);
    }
    return _enterBtn;
}

- (XOWMLabel *)zffsLBL
{
    if (!_zffsLBL)
    {
        _zffsLBL = [[XOWMLabel alloc]initWithText:@"选择方式"];
        _zffsLBL.textColor = RGBA(109, 109, 109, 1.0);
        _zffsLBL.font = [UIFont systemFontOfSize:17 weight:UIFontWeightBold];
        [self addSubview:_zffsLBL];
        _zffsLBL.c_top.equal(self.moneyLBL.c_bottom).with.coffset(GAP);
        _zffsLBL.c_left.equal(self).with.coffset(GAP);
        _zffsLBL.c_size.equal(_zffsLBL.bounds.size);
    }
    return _zffsLBL;
}

- (XOWMOrderLBL *)gameLBL
{
    if (!_gameLBL)
    {
        _gameLBL = [[XOWMOrderLBL alloc]initWithTitle:@"商品信息"];
        [self addSubview:_gameLBL];
        _gameLBL.c_top.equal(self.line.c_bottom);
        _gameLBL.c_left.equal(self).with.coffset(GAP);
        _gameLBL.c_right.equal(self).with.coffset(-GAP);
        _gameLBL.c_height.equal(H);
    }
    return _gameLBL;
}

- (XOWMOrderLBL *)moneyLBL
{
    if (!_moneyLBL)
    {
        _moneyLBL = [[XOWMOrderLBL alloc]initWithTitle:@"商品金额"];
        [self addSubview:_moneyLBL];
        _moneyLBL.c_top.equal(self.gameLBL.c_bottom);
        _moneyLBL.c_left.equal(self).with.coffset(GAP);
        _moneyLBL.c_right.equal(self).with.coffset(-GAP);
        _moneyLBL.c_height.equal(H);
    }
    return _moneyLBL;
}

- (void)yjd_zhanshi:(NSString *)xiabiao mz:(NSString *)mz tp:(NSString *)tp;
{
    NSArray *arr1 = [xiabiao componentsSeparatedByString:@","];
    NSArray *arr2 = [mz componentsSeparatedByString:@","];
    NSArray *arr3 = [tp componentsSeparatedByString:@","];
    
    if (arr1.count < 1)
        return;
    
    for (int i = 0; i < arr1.count; i ++)
    {
        int num = [arr1[i] intValue];
        NSString *zfmz = arr2[i];
        NSString *zftp = arr3[i];
        XOWMSegBtn *segBtn = [[XOWMSegBtn alloc]initWithTitle:zfmz icon:zftp];
        segBtn.tag = 200 + num;
        [segBtn addTarget:self action:@selector(yjd_SegBtnMethod:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:segBtn];
        segBtn.c_top.equal(self.moneyLBL.c_bottom).with.coffset(H * i);
        segBtn.c_left.equal(self.zffsLBL.c_right).with.coffset(GAP);
        segBtn.c_right.equal(self).with.coffset(-GAP);
        segBtn.c_height.equal(H);
    }
}

- (void)yjd_productInfo:(XOWMProduct *)product
{
    if (product)
    {
        self.gameLBL.content = product.goodsTitle;
        self.moneyLBL.content = [NSString stringWithFormat:@"¥%@",product.goodsPrice];
    }
}

- (void)yjd_aciontForCancelBtn
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_actionWithSubViewEvent:)])
    {
        [self.delegate yjd_actionWithSubViewEvent:YJDzfshituEventBack];
    }
}

- (void)yjd_closeEnterBtn
{
    self.enterBtn.userInteractionEnabled = NO;
    [self.enterBtn setBackgroundColor:TEXT_GRAY_COLOR];
}

- (void)yjd_openEnterBtn
{
    self.enterBtn.userInteractionEnabled = YES;
    [self.enterBtn setBackgroundColor:[XOWMHelper shareHelp].color];

}

- (void)yjd_actionForEnterBtn
{
    BOOL selected = NO;
    for (UIView *view in [self subviews]) {
        if (view.tag > 200)
        {
            XOWMSegBtn * button = (XOWMSegBtn *)view;
            if (button.selected && self.delegate  && [self.delegate respondsToSelector:@selector(yjd_actionForSelectWay:)])
            {
                selected = YES;
                [self.delegate yjd_actionForSelectWay:(int)button.tag - 200];
                return;
            }
        }
    }
    if (!selected)
    {
        [CCAlert showMessage:@"先选择一种方式" hidden:nil];
    }
}

- (void)yjd_SegBtnMethod:(XOWMSegBtn *)sender
{
    sender.selected = YES;
    for (UIView *view in [self subviews])
    {
        if (view.tag > 200 && view.tag != sender.tag)
        {
            XOWMSegBtn * button = (XOWMSegBtn *)view;
            button.selected = NO;
        }
    }
}


/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */


- (void)sp_didUserInfoFailed:(NSString *)mediaInfo {
    NSLog(@"Get Info Failed");
}
@end
